package com.best.guanfengji.serial_port

import java.util.Timer
import java.util.TimerTask


/**
 * author: shihao
 * date: 2021/4/9 15:43
 * description:
 */
object SerialPortCommand {
    /**
     * 数据包头
     */
    const val CMD_HEADER = "7E7E"

    /**
     * 设置主机地址为5A
     */
    const val SETTING_ADDRESS_5A = "F15A"

    /**
     * 节点地址
     */
    const val BOARD_NODE = ""

    /**
     * 主命令
     */
    val mainCMD: MainCMD = MainCMD()
    class MainCMD{
        private var y14:String = "00"//移料抓上
        private var y13:String = "00"//移料抓下
        private var y10:String = "00"//焊后修剪
        private var y17:String = "00"//焊接启动
        private var y9:String = "00"//焊接夹紧
        private var y8:String = "00"//注液插入
        private var y7:String = "00"//边角切除
        private var y6:String = "00"//吹气定型
        private var y5:String = "00"//吹气插入
        private var y4:String = "00"//合模气缸
        private var y1:String = "00"//料筒升起
        private var y2:String = "00"//原料热切
        private var y12:String = "00"//移料气缸
        private var y3:String = "00"//取料气缸
        private var y16:String = "00"//挤料电机开关

        /**
         * 移料抓上
         */
        fun executeY14(status: Int):String{
            y14 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "14" + y14
        }
        /**
         * 移料抓下
         */
        fun executeY13(status: Int):String{
            y13 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "13" + y13
        }
        /**
         * 焊后修剪
         */
        fun executeY10(status:Int):String{
            y10 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "10" + y10
        }
        /**
         * 焊接启动
         */
        fun executeY17(status:Int):String{
            y17 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "17" + y17
        }
        /**
         * 焊接夹紧
         */
        fun executeY9(status:Int):String{
            y9 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "09" + y9
        }
        /**
         * 注液插入
         */
        fun executeY8(status:Int):String{
            y8 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "08" + y8
        }
        /**
         * 边角切除
         */
        fun executeY7(status:Int):String{
            y7 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "07" + y7
        }
        /**
         * 吹气定型
         */
        fun executeY6(status:Int):String{
            y6 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "06" + y6
        }
        /**
         * 吹气插入
         */
        fun executeY5(status:Int):String{
            y5 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "05" + y5
        }
        /**
         * 合模气缸
         */
        fun executeY4(status:Int):String{
            y4 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "04" + y4
        }
        /**
         * 料筒升起
         */
        fun executeY1(status:Int):String{
            y1 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "01" + y1
        }
        /**
         * 原料热切
         */
        fun executeY2(status:Int):String{
            y2 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "02" + y2
        }
        /**
         * 移料气缸
         */
        fun executeY12(status:Int):String{
            y12 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "12" + y12
        }
        /**
         * 取料气缸
         */
        fun executeY3(status:Int):String{
            y3 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "03" + y3
        }
        /**
         * 挤料电机开关
         */
        fun executeY16(status:Int):String{
            y16 = "0${status}"
            return CMD_HEADER + BOARD_NODE + "16" + y16 + "64"
        }
    }


    /**
     * 定量注液
     * @param rating 方向 01正向 02反向
     */
    fun injectSolution(pulse:String,rating:String):String{
        return CMD_HEADER + BOARD_NODE + "23" + pulse + rating + "02"
    }

    /**
     * 协议响应回馈
     */
    fun feedback(cmd:String):String{
        return CMD_HEADER + BOARD_NODE + cmd
    }

    /**
     * 获取限位状态
     */
    fun getXState():String{
        return CMD_HEADER + BOARD_NODE + "30"
    }

}